How do I check If a Class already exists in Ruby - Stack Overflow
if defined?(MyClassName) == 'constant' && MyClassName.class == Class
puts "its a class"
end
Time to sit down and reflect.
How do I check If a Class already exists in Ruby - Stack Overflow
if defined?(MyClassName) == 'constant' && MyClassName.class == Class
puts "its a class"
end
Time to sit down and reflect.
So, yesterday I used Exec to outsource an errand. I tried to be as specific as possible: go to Costco, buy a box of 30 Rockstar drinks, a bag of Mach 3 razors, then bring them to my office. I got four calls from my Exec:
It’s not as much work as going to Costco myself, but it was more work than I was expecting. It was because I hadn’t specified things correctly, or been specific enough to say “just use your best judgement”.
I think all outsourcing is like that - whether you’re outsourcing personal assistant-type tasks, programming tasks, taxes, or anything else. Outsourcing requires you to be extremely specific about what inputs you’re providing and what kinds of output you expect. It looks a lot like a function definition. Like pseudocode. There’s a lot in common there with actually programming a computer.
So, last weekend most of our leadership ran off to Coachella. They took off Friday and Monday to enjoy the show and get a much-needed break. The rest of us proceeded to work on schedule since Heyzap is Serious Business (tm), but I couldn’t resist the opportunity for a little prank.
Heyzap has a number of stuffed animals about the office. They make great items to twirl while you’re thinking about massive problems, or nice little guys to cuddle while you’re taking a power nap. Also, I’d been playing a lot of Batman: Arkham City lately, and this guy kinda stuck with me:
Somehow, the two clicked in my head, and I decided to set up my own convoluted set of riddles and take my own set of hostages. Thus began the adventure!
I knew I wanted something you could call in to. Sure, you could leave text clues around the office, or have a web site you go to or something, but there’s something old-school about a voice on the phone taunting you. It’s in so many movies. And having a scrambled, spooky, hostage-taker voice is way more engaging than plain text clues. It’s the kind of gag that brings it from frustrating mini-game to fun adventure. So, how do we set up that kind of thing? I used Twilio.
I bought a phone number from them, which you can do for $1 / month using their API Explorer Tool, then set up an application on my existing (shared, php) web hosting. I set up a quick git repo and Capistrano deploy script, and I was ready to go! The php application is insanely simple - basically a copy of their Hello Monkey tutorial. The whole source code for my app is on my github if you’re interested, but here’s the relevant part:
<Response>
<?php if(file_exists($_SERVER{'DOCUMENT_ROOT'} . "/assets/". $_REQUEST['Digits'] . ".mp3")) { ?>
<Play><?php echo "http://judeprank.atevans.com/assets/". $_REQUEST['Digits'] . ".mp3?version=3" ?></Play>
<?php } else { ?>
<Play>http://judeprank.atevans.com/assets/99999999.mp3</Play>
<?php } ?>
</Response>
Important Note: sending the version number in the url is critical. That way, if you change any of the .mp3 files, you can bump the version number. Otherwise, Twilio will cache the file indefinitely, and keep playing the old one after you’ve posted an update. Also, this may not be super secure, since you can find out if hidden files exist, but I don’t have anything I’m worried about on this server.
Anyway, that done, I popped open IRB and used this function (rand * 100000000).to_i
to generate a bunch of random 8-digit codes. I didn’t want them to be able to figure out the file names from clues or anything else, so I figured 8 digits of entropy on a phone number was good enough to prevent brute-forcing attacks.
Finally, I came up with a bunch of clues and recorded them using GarageBand. I made up a set of Voice distortions so the bosses wouldn’t know it was me, and the voice would sound suitably serious. You can download the GarageBand file here.
So, once I had some codes and some clues, I just had to print out some paper (gasp!) with the codes on it and distribute it around the office. Here’s the guided tour.
A note left on the desk – 99999999
Welcome to my game. if you win, you will get a reward. if not, the hostages will die. To begin, enter the code 98314335
Voice Link
From the phone call – 98314335
The rest of the codes are hidden in the office. Here's your clue for the first one. We see awesomeness every monday. But what's BEHIND the awesomeness?
Voice Link
This is a reference to our weekly monday meetings, which always begin with a slide entitled “Heyzap Awesomeness”
Behind TV in conference room – 61034608
Good guess, but the real secret is what's on the inside. Something... alcoholic.
Voice Link
Taped inside kegganator door – 97372993
Now you're getting it. Your next clue is behind the least-used computer in the office.
Voice Link
Behind computer in bike room – 56303035
The next clue requires a green thumb, and a power cord.
Voice Link
In the cell phone garden – 49076981
You'd better hurry, or i will kill one of the hostages.
The paperless office is a universal dream. Your next clue is a nightmare.
Voice Link
We only have one filing cabinet in the office. I also left a threatening note with this one for effect. Yes, that is a nerf gun.
Behind the filing cabinet – 29175769
You're doing well. The clues will get harder from here.
You may need to use some collective intelligence to find the next one.
Voice Link
Inside collective intelligence book – 73433093
The next clue is a hairy one - red and hairy.
Voice Link
We have a red-colored wig in our cupboards that’s supposed to look like Jude’s hair. Don’t ask.
Under the Jude wig on the shelves – 76145273
Remember when you could find a toy in your box of cheerios?
Voice Link
Behind the cheerios in the kitchen – 19626037
From here you can see dinosaurs, plumbers, and how you're a pawn in my little game. I am underneath.
Voice Link
Under the orange couch in the game room – 28836890
Almost there.
Your last clue is in cryostasis.
Voice Link
In the bottom drawer of the freezer – 13143233
Congratulations! The countdown timer has five minutes left.
The best view isn't in the office, it's up the corporate ladder.
Voice Link
The hostages are on the roof.
With a few toys for the hunters.
Well, to be honest, this didn’t go as well as I’d hoped.
Our company president got the message shortly after he got in on Tuesday. I noticed him showing our CTO, but I didn’t say anything - the whole point of this was to be anonymous, right?
Well, then he just kinda sat at his computer doing work. Darn. We had our regular meetings and such, and got right back to business. I figured maybe he intended to check it out after work, so I stayed a bit late. Then our CTO realized that the whole Coachella crew was also booked to go see Rusko after work, around 8pm or so, later that night. Well.
The next day, Jude and crew were at work as normal, and there was no sign of disruption in the office whatsoever. Jude came over once to ask me if the code wasn’t working (I presume our office admin - my co-conspirator - ratted me out), then proceeded to dial in, enter a code, then say “Oh wait, I hear a clue!” then dash off. Hmmmmm.
By 7pm on the third day, it started raining. I had placed a tarp over the office animals in case it rained on them Monday night, but I didn’t think it would go on quite that long. I went ahead an rescued the animals myself and took down all the clues. I guess I miscalculated on Jude’s busy-ness, his interest in adventure pranks, or maybe the Twilio app wasn’t working on our office Cisco phones for some reason.
Regardless, I guess unlike the Riddler, I totally won this round. The great Jude Gomila was no match for the intellect of Captain Conundrum! A little disappointing, but perhaps life isn’t like in the comic books.
Anyway, next time I’m changing Jude’s computer password and hiding that.
Hopefully someone else finds this collection of shenanigans useful. If you want some help organizing a prank, hit me up on twitter, facebook, or via email – I love this kinda stuff.
I showed Jude this blog post, and when he got to the first clue he said “Wait, I’m going to solve this!” Then proceeded to figure out all the riddles without looking at the post, with me to confirm / deny answers. Also, he said he talked to me because “only you would set something like this up”, not because anyone squealed. Cool!
And a few bugs in the process: the first piece of paper only had seven numbers - you have to enter eight digits to get the response. Fail! Also, a combination of effects may have made this harder: Twilio, the carriers, or phone speakers degrade the quality on the voice recordings significantly. I checked with a few other people before Jude got back to make sure they could understand it, but Jude still could only get about half of it. Maybe Coachella did a number on the attendee’s hearing.
All in all a fun time, hope to pull a stunt like this again some day.
I think we can do better than that. We can respond constructively. I propose that we collectively build an informal “Smart Game Catalog.” Nothing official. No effort to be comprehensive. Simply an invitation to pitch a game you consider “artistic or intellectually sophisticated” and explain why you think so. If you disagree with Clark’s bleak assessment, counter with a helpful response.
Brainy Gamer: I got your smart games right here.
Smart idea.
require 'job_interview'
@answer = JobInterview::Answer.new
@answer.fizz_buzz(5)
=> [1, 2, "Fizz", 4, "Buzz"]
@answer.fib(10)
=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
@answer.quine(__FILE__)
=> "@answer.quine(__FILE__)"
@answer.primes(10)
=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
This is great. Hope I can use this next time I’m white-boarding some code.
Here’s a task I wrote for Exec, the instant personal assistant service.
Useful for emergency mornings – you know, the ones where you really have to get up and moving quickly.
Updated my gist for creating a new Jekyll post. Now generates images for posts with a max size of 600x600 using RMagick. Not hard to change if you need a different size. :)
As such, we are proud to say that we value:
…
Not being a dick over being a rockstar
That is to say, we value the things on the left more than we value the things on the right. And some of the things on the right aren’t even on our radar.
If you:
Write a technical blog
Contribute to open source projects
Attend user groups in your spare time
Mostly only read books about coding and productivity
Push to GitHub while sitting on the toilet
Are committed to maximum awesomeness at all times, or would have us believe it
…we respect you for it. There’s probably some pity in there too
Wow, way to not be a dick.